#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    vector<int> ans;
    vector<int> getSumAbsoluteDifferences(vector<int>& nums)
    {
        int n = nums.size();
        ans.resize(n);
        int lSum = 0;
        int rSum = accumulate(nums.begin(), nums.end(),0);//总的右和就是当前的所有前缀和
        int nowSum = 0;//当前前缀和
        for (int i = 0; i < n; i++)
        {
            rSum -= nums[i];
            ans[i] = i * nums[i] - lSum + rSum - (n - i - 1) * nums[i] ;
            lSum += nums[i];
        }
        return ans;
    }
};